package com.edu.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.edu.exception.FileException;
import com.edu.service.FileService;
import com.edu.vo.PageUtils;
import com.edu.vo.ResultVO;
import com.edu.vo.ServerConstant;
import com.edu.vo.SimpleTree;

@RestController
@RequestMapping("/tree")
public class TreeController {

    @Autowired
    private FileService fileService;
    private final Logger logger = LoggerFactory.getLogger(this.getClass());


    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public PageUtils getFileTree() {
        logger.debug("获取文件树");
        PageUtils pages = null;
        try {
            SimpleTree fileTree = fileService.getFileTree();
            pages = new PageUtils(fileTree.getNodes(), fileTree.getNodes().size());
        } catch (FileException e) {
            logger.error(e.getMessage());
            pages = new PageUtils(ServerConstant.SERVER_INTERNAL_ERROR, e.getMessage());
        }
        return pages;
    }
}
